package ua.kpi_java_training.evgeniygusar.module3;

import java.util.ArrayList;
import java.util.HashSet;

public class AllObstacles {
    static private ArrayList<Obstacle> obstacles = new ArrayList<Obstacle>();

    private static final HashSet<Integer> obstaclesXCoordinats = new HashSet<Integer>();
    private static final HashSet<Integer> obstaclesYCoordinats = new HashSet<Integer>();

    public boolean checkObstacleInXY(int x, int y) {
        for (int currentIndexOfObstacle = 0; currentIndexOfObstacle<= obstacles.size()-1; currentIndexOfObstacle++)
            if ((obstacles.get(currentIndexOfObstacle).x == x) & (obstacles.get(currentIndexOfObstacle).y == y))
                return true;
        return false;
    }

    /**
     * Method for adding new x coordinat of obstacle to obstaclesXCoordinats HashSet
     * @param x - x cordinat of new obstacle
     */

    public Boolean addX(int x) {
        return obstaclesXCoordinats.add(x);
    }

    /**
     * Method for adding new y coordinat of obstacle to obstaclesYCoordinats HashSet
     * @param y - y cordinat of new obstacle
     */

    public Boolean addY(int y) {
        return obstaclesYCoordinats.add(y);
    }

    /**
     * Adding new obstacle to obstacles ArrayList
     */


    public void addObstacle() {
        obstacles.add(new Obstacle());
        System.out.println("Obstacle " + obstacles.size() + " is created!");
        obstacles.get(obstacles.size()-1).showCoordinats();
    }

    /**
     * Getter for numbers of obstacles
     */

    public int numbersOfObstacles() {
        return obstacles.size();
    }

    /**
     * Getter for obstacle object with certain index
     */

    public Obstacle getObstacle(int indexOfObstacle) {
        return obstacles.get(indexOfObstacle);
    }
}
